<?php

namespace app\admin\controller;

use app\BaseController;
use app\common\result\Result;
use app\model\Order as ModelOrder;
use EasyWeChat\OfficialAccount\Application;
use think\facade\Request;
use think\facade\Env;

/**
 *
 */
class Order extends BaseController
{

    /**
     * @var string[]
     */
    protected $middleware = [
        'auth',
        'checkPermission'
    ];

    /**
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $pageNum = Request::param('pageNum');
        $pageSize = Request::param('pageSize');

        $list = ModelOrder::page($pageNum, $pageSize)->order('id', 'desc')->select();
        return Result::Success($list);
    }

    public function getWechatApp()
    {
        $app_id = Env::get('easywechat.app_id');
        $secret = Env::get('easywechat.secret');
        $token = Env::get('easywechat.token');
        $aes_key = Env::get('easywechat.aes_key');

        $config = [
            'app_id' => $app_id,
            'secret' => $secret,
            'token' => $token,
            'aes_key' => $aes_key,
        ];
        $app = new Application($config);
        return $app;
    }
}
